<template>
	<view class="content">
		<swiper class="swiperBox">
			<swiper-item class="swiperItem">
			</swiper-item>
			<!-- <swiper-item class="swiperItem">
			</swiper-item> -->
			<!-- <swiper-item class="swiperItem">
				<image :src="baseurl+'index/bg2.jpg'" class="swiperImg"></image>
			</swiper-item> -->
		</swiper>
		<!-- <image :src="baseurl+'index/bg1.jpg'" class="bg" v-if="menuIndex==0"></image>
		<image :src="baseurl+'index/bg2.jpg'" class="bg" v-else></image> -->
		<image :src="baseurl+menuBtn" class="menuBtn"></image>
		<button open-type='contact' class="service"></button>
		<image :src="baseurl+'index/start.png'" class="start"
			@click="menuIndex==0?$navto.navto('/packageB/mtzd_info/mtzd_info'): $navto.navto('/packageB/mtmh_info/mtmh_info')">
		</image>
		<!-- <view class="arrowBox">
			<image :src="baseurl+'index/arrowleft.png'" class="arrow"></image>
			<image :src="baseurl+'index/arrowright.png'" class="arrow"></image>
		</view> -->
		<!-- <view class="tabBarBox" v-if="isTab==1">
			<image src="@/static/tab/bg.png" class="tabbg"></image>
			<image src="@/static/tab/1.png" class="projectTab" @click="$redirectTo('/packageB/project/project')">
			</image>
			<image src="@/static/tab/2.png" class="associationTab"
				@click="$redirectTo('/packageB/association/association')"></image>
			<image src="@/static/tab/3s.png" class="homeTab" @click="$redirectTo('/pages/index/index')"></image>
			<image src="@/static/tab/4.png" class="mallTab" @click="$redirectTo('/packageB/category/category')"></image>
			<image src="@/static/tab/5.png" class="myTab" @click="$redirectTo('/pages/user/user')"></image>
		</view> -->
		<!-- <view class="tabBarBox" v-else> -->
			<!-- <image src="@/static/tab/bg.png" class="tabbg"></image> -->
			<!-- 	<image src="@/static/tab/1.png" class="projectTab" @click="$redirectTo('/packageB/project/project')">
			</image> -->
			<!-- <image src="@/static/tab/2.png" class="associationTab"@click="$redirectTo('/packageB/association/association')"></image> -->
			<!-- <image src="@/static/tab/3s.png" class="homeTab" @click="$redirectTo('/pages/index/index')"></image> -->
			<!-- <image src="@/static/tab/4.png" class="mallTab" @click="$redirectTo('/packageB/category/category')"></image> -->
			<!-- <image src="@/static/tab/5.png" class="myTab" @click="$redirectTo('/pages/user/user')"></image> -->
		<!-- </view> -->
		<view class="tabBarBox" v-if="isTab==1">
			<image src="@/static/tab/bg.png" class="tabbg"></image>
			<image src="@/static/tab/1.png" class="projectTab" @click="$redirectTo('/packageB/project/project')">
			</image>
			<image src="@/static/tab/2.png" class="associationTab"
				@click="$redirectTo('/packageB/association/association')"></image>
			<image src="@/static/tab/3s.png" class="homeTab" @click="$redirectTo('/pages/index/index')"></image>
			<image src="@/static/tab/4.png" class="mallTab" @click="$redirectTo('/packageB/category/category')"></image>
			<image src="@/static/tab/5.png" class="myTab" @click="$redirectTo('/pages/user/user')"></image>
		</view>
		<view class="tabBarBox" v-else>
			<image src="@/static/tab/bg.png" class="tabbg"></image>
			<image src="@/static/tab/1.png" class="projectTab" @click="$redirectTo('/packageB/project/project')">
			</image>
			<!-- <image src="@/static/tab/2.png" class="associationTab"@click="$redirectTo('/packageB/association/association')"></image> -->
			<image src="@/static/tab/3s.png" class="homeTab" @click="$redirectTo('/pages/index/index')"></image>
			<!-- <image src="@/static/tab/4.png" class="mallTab" @click="$redirectTo('/packageB/category/category')"></image> -->
			<!-- <image src="@/static/tab/5.png" class="myTab" @click="$redirectTo('/pages/user/user')"></image> -->
		</view>
		<view class="adsBox" v-if="data.length>0&&isAds==true&&isTab==1">
			<image :src="data[0].image" class="sign" @click="toInfo()"></image>
			<image :src="baseurl+'index/close.png'" class="close" @click="isAds=!isAds"></image>
		</view>
	</view>
</template>

<script>
	import Cache from '@/utils/cache'
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	const app = getApp()
	export default {
		data() {
			return {
				baseurl: this.$baseurl,
				menuBtn: 'index/mtzd.png',
				menuIndex: 0,
				isAds: true,
				data: '',
				isTab: '',
				versions: ''
			}
		},
		onShow() {
			this.$request.get(`Community/submit_status`).then(res => {
				this.isTab = res.data.data;
			})
		},
		onLoad() {
			const updateManager = wx.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				// 请求完新版本信息的回调
				console.log(res.hasUpdate)
			})
			updateManager.onUpdateReady(function() {
				wx.showModal({
					title: '更新提示',
					content: '新版本已经准备好，是否重启应用？',
					success: function(res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate()
						}
					}
				})
			})
			updateManager.onUpdateFailed(function() {
				// 新版本下载失败
			})
			this.getUser();
			// 获取广告
			uni.hideHomeButton()
			// 在代码中判断

			const accountInfo = uni.getAccountInfoSync();
			console.log(accountInfo.miniProgram.envVersion)
			if (accountInfo.miniProgram.envVersion === 'trial' || accountInfo.miniProgram.envVersion === 'develop') {
				this.versions = 1;
				console.log('这是测试版');
			} else {
				console.log('这是正式版');
				this.versions = 2;
			}
			this.$request.get(`ad/lists?pid=8&versions=${this.versions}`).then(res => {
				this.data = res.data.data;
			})
		},
		methods: {
			...mapActions(['getCartNum', 'getUser']),
			toInfo() {
				if (this.data[0].link.includes("https")) {
					console.log("字符串包含https");
					this.$navto.navto('/packageB/webview/webview',{url:this.data[0].link})
				} else {
					let url = this.data[0].link.split('?')[0];
					let id = this.data[0].link.split('=')[1];
					this.$navto.navto(url, {
						id: id
					});
				}
			}
		},
		computed: {
			...mapGetters(['userInfo', 'inviteCode', 'appConfig']),
		}
	}
</script>

<style lang="scss" scoped>
	.adsBox {
		position: fixed;
		width: 100%;
		height: 100vh;
		left: 0;
		top: 0;
		background-color: rgba(0, 0, 0, 0.7);
		z-index: 999;

		.sign {
			width: 700rpx;
			height: 812rpx;
			margin-left: 25rpx;
			margin-top: 300rpx;
		}

		.close {
			width: 75rpx;
			height: 75rpx;
			margin-left: 340rpx;
			margin-top: 70rpx;
		}
	}

	@keyframes flash {
		0% {
			opacity: 0;
		}

		100% {
			opacity: 1;
		}
	}

	.arrowBox {
		position: absolute;
		width: 674rpx;
		margin-left: 38rpx;
		top: 732rpx;
		z-index: 1;
		display: flex;
		justify-content: space-between;
		animation: flash 1s 0s linear both infinite alternate;

		.arrow {
			width: 24rpx;
			height: 40rpx;
		}
	}

	.start {
		position: absolute;
		width: 297rpx;
		height: 85rpx;
		margin-left: 227rpx;
		top: 433rpx;
		z-index: 1;
	}

	.service {
		position: relative;
		width: 80rpx;
		height: 80rpx;
		margin-top: 650rpx;
		margin-left: 644rpx;
		z-index: 1;
		background: url('https://miantou.guguan.net/img/index/service.png');
		background-size: 100% 100%;
	}

	.menuBtn {
		position: relative;
		width: 520rpx;
		height: 66rpx;
		margin-top: 276rpx;
		margin-left: 115rpx;
		z-index: 1;
	}

	.bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 1624rpx
	}

	.swiperBox {
		position: absolute;
		width: 100%;
		height: 100vh;
		top: 0;
		left: 0;
		background: url('https://miantou.guguan.net/img/index/bg1.jpg');
		background-size: 100% 100%;

		.swiperItem,
		.swiperImg {
			width: 100%;
			height: 100%;
		}
	}

	.content {
		width: 100%;
		height: 100%;
	}
</style>